/**
 * Created by Administrator on 15-10-8.
 */

window.onload=function(){
    var userid=getUserId();
    var url = getUrl();
    $.jsonp({
        url: 'http://'+url+'/api/user/user_cluck_list',
        data: {userId:userid},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {
            //console.log(data);
            $.each(data.arrays,function(index,ele){

                var sex=ele.sex;
                var sexstr='icons-sex-female';
                var sexbgstr='sex sex-female';
                if(sex==1){
                    sexstr="icons-sex-male";
                    sexbgstr='sex sex-male';
                }
                var html='<li>' +
                    '<div class="order-list-avatar">' +
                    '<a href="tade.html?id='+ele.cluckId+'">' +
                    '<img src="'+ele.photo+'" alt=""></a>' +
                    '</div>' +
                    '<div class="order-list-intro">' +
                    '<div class="order-list-intro-text">' +
                    '<a href="tade.html?id='+ele.cluckId+'">' +
                    '<p class="color666 fz14">'+ele.nickName+'</p>' +
                    '<p class="color666 fz14"><span class="'+sexbgstr+'"><i class="'+sexstr+'"></i>'+ele.age+'</span></p>' +
                    '</a>' +
                    '</div>' +
                    '<div class="order-list-intro-button w_abc">' +
                    '<a data-gz="'+ele.cluckId+'" href="javascript:void(0); "class="edit" style=" color:#c5c5c5; border:1px solid #c5c5c5;">已关注</a>' +
                    '</div>' +
                    '</div>' +
                    '</li>';
                    $("#wdgz").append(html);
            })
            //判断是否关注
            var tadeuserid=data.userId;
            $.jsonp({
                url: 'http://'+url+'/api/user/user_cluck_list',
                data: {userId:userid},
                callbackParameter: "callback",
                success: function (data,textStatus,xOptions) {
                    $.each(data.arrays,function(index,ele){
                        if(ele.cluckId==tadeuserid){
                            $(".edit").text("已关注").css({'color': '#c5c5c5','border':'1px solid #c5c5c5'});
                        }

                    });
                    $(".edit").show();
                },
                error: function (xOptions, textStatus) {
                }

            });
        },
        error: function (xOptions, textStatus) {

        }

    });

    $(document).on('click','.edit',function(){
        var userId=$(this).data('gz');
        var _txt=$(this).text();
        var obtn=this;
        $.jsonp({
            url: 'http://'+url+'/api/user/cluck_user-'+userId,
            data: {userId:userid},
            callbackParameter: "callback",
            success: function (data, textStatus, xOptions) {
                //console.log(data);
                var code = data.code;
                if(code==1) {
                    $(obtn).removeClass("btn").text("已关注").css({color: '#c5c5c5', 'border': '1px solid #c5c5c5'});
                    showToast("关注成功");
                }else{
                    $(obtn).addClass("btn").text("+关注").css({color: '#00a5e0', width: '60px', height: '30px', 'padding':'0','border':'1px solid #00a5e0'});
                    showToast("取消关注成功");
                }
            },
            error: function (xOptions, textStatus) {
            }
        });

    })
}
